//
//  UIBarButtonItem+Extension.swift
//  ZBWb
//
//  Created by 天隐翎 on 16/4/10.
//  Copyright © 2016年 csdn. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    convenience init(imageName: String? = nil,title: String? = nil,target: AnyObject?, action: Selector) {
        self.init()
        let btn = UIButton()
//        添加点击事件
        btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
//        设置图片
        if let imag = imageName{
            
            btn.setImage(UIImage(named: imag), forState: .Normal)
            btn.setImage(UIImage(named: imag + "_highlighted"), forState: .Highlighted)
            
    }
//        设置文字大小
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        btn.setTitle(title, forState: .Normal)
        
//        设置文字颜色
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        
//        设置大小
        btn.sizeToFit()
        
        customView = btn
    }
    
    
    
    
}
